public class StringBufferDemo {
    public static void main(String[] args) {
        String str = "A dog is a kind of animal";
        StringBuilder sb = new StringBuilder(str);

        int index = sb.indexOf("dog");
        if (index != -1) {
            sb.replace(index, index + 3, "cat");
        }

        System.out.println(sb);
    }
}
